﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using Fulcrum.ControlGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.ControlGenerator
{
    [TestClass]
    public class RoutedEventXmlConfigurationTests
    {
        public RoutedEventXmlConfigurationTests()
        {
            // nothing
        }

        const string StandardXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='MyHandlerType' summary='my summary' remarks='my remarks'></blah>";
        const string EmptyNameXml = "<blah name='' eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='MyHandlerType' summary='my summary' remarks='my remarks'></blah>";
        const string MissingNameXml = "<blah eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='MyHandlerType' summary='my summary' remarks='my remarks'></blah>";
        const string EmptyEventArgsTypeXml = "<blah name='my name' eventArgsType='' strategy='my strategy' handlerType='MyHandlerType' summary='my summary' remarks='my remarks'></blah>";
        const string MissingEventArgsTypeXml = "<blah name='my name' strategy='my strategy' handlerType='MyHandlerType' summary='my summary' remarks='my remarks'></blah>";
        const string EmptyRoutingStrategyXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='' handlerType='MyHandlerType' summary='my summary' remarks='my remarks'></blah>";
        const string MissingRoutingStrategyXml = "<blah name='my name' eventArgsType='MyEventArgsType' handlerType='MyHandlerType' summary='my summary' remarks='my remarks'></blah>";
        const string EmptyHandlerTypeXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='' summary='my summary' remarks='my remarks'></blah>";
        const string MissingHandlerTypeXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='my strategy' summary='my summary' remarks='my remarks'></blah>";
        const string EmptySummaryXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='MyHandlerType' summary='' remarks='my remarks'></blah>";
        const string MissingSummaryXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='MyHandlerType' remarks='my remarks'></blah>";
        const string EmptyRemarksXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='MyHandlerType' summary='my summary' remarks=''></blah>";
        const string MissingRemarksXml = "<blah name='my name' eventArgsType='MyEventArgsType' strategy='my strategy' handlerType='MyHandlerType' summary='my summary' ></blah>";
        const string MissingEventArgsAndHandlerTypesXml = "<blah name='my name' strategy='my strategy' summary='my summary' remarks='my remarks'></blah>";

        [TestMethod]
        public void TestReaderAdvancement()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            Assert.IsTrue(xmlReader.IsStartElement());

            var config = new RoutedEventXmlConfiguration(xmlReader);

            Assert.IsFalse(xmlReader.IsStartElement());
        }

        [TestMethod]
        public void TestEventArgsType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("MyEventArgsType", config.EventArgsType);
        }

        [TestMethod]
        public void TestMissingEventArgsType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingEventArgsTypeXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("RoutedEventArgs", config.EventArgsType);
        }

        [TestMethod]
        public void TestEmptyEventArgsType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyEventArgsTypeXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.EventArgsType);
        }

        [TestMethod]
        public void TestHandlerType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("MyHandlerType", config.HandlerType);
        }

        [TestMethod]
        public void TestMissingHandlerType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingHandlerTypeXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("EventHandler<MyEventArgsType>", config.HandlerType);
        }

        [TestMethod]
        public void TestEmptyHandlerType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyHandlerTypeXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.HandlerType);
        }

        [TestMethod]
        public void TestName()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("my name", config.Name);
        }

        [TestMethod]
        public void TestMissingName()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingNameXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.IsNull(config.Name);
        }

        [TestMethod]
        public void TestEmptyName()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyNameXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.Name);
        }

        [TestMethod]
        public void TestRemarks()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("my remarks", config.Remarks);
        }

        [TestMethod]
        public void TestMissingRemarks()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingRemarksXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.IsNull(config.Remarks);
        }

        [TestMethod]
        public void TestEmptyRemarks()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyRemarksXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.Remarks);
        }

        [TestMethod]
        public void TestRoutingStrategy()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("my strategy", config.RoutingStrategy);
        }

        [TestMethod]
        public void TestMissingRoutingStrategy()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingRoutingStrategyXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("Bubble", config.RoutingStrategy);
        }

        [TestMethod]
        public void TestEmptyRoutingStrategy()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyRoutingStrategyXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.RoutingStrategy);
        }

        [TestMethod]
        public void TestSummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("my summary", config.Summary);
        }

        [TestMethod]
        public void TestMissingSummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingSummaryXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.IsNull(config.Summary);
        }

        [TestMethod]
        public void TestEmptySummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptySummaryXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("", config.Summary);
        }

        [TestMethod]
        public void TestMissingEventArgAndHandlerTypes()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingEventArgsAndHandlerTypesXml);

            var config = new RoutedEventXmlConfiguration(xmlReader);
            Assert.AreEqual("RoutedEventHandler", config.HandlerType);
        }

    }
}
